package com.zenni.core;

import com.zenni.utils.DriverUtils;
import org.apache.log4j.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;

/**
 * Created by douglasj on 3/7/16.
 */
public class CartFunction {
    private WebDriver driver = null;
    private DriverUtils driverUtils = new DriverUtils();
    Logger logger = Logger.getLogger(this.getClass().getName());
    public CartFunction(WebDriver driver) throws Exception{
        this.driver = driver;
    }
    public String getCartPageTitle() throws Exception{
        String cartpagetitle = driver.findElement(By.xpath(CartPageVariables.cart_page_title_xpath)).getText();
        return cartpagetitle;
    }
    public void enterPromoCode(String promocode) throws Exception{
        driver.findElement(By.id(CartPageVariables.promo_code_textbox_id)).sendKeys(promocode);
    }
    public void submitPromoCode() throws Exception{
        driver.findElement(By.id(CartPageVariables.promo_code_submit_button_id)).click();
    }
    public void clickUpdateCartButton() throws Exception{
        driver.findElement(By.id(CartPageVariables.update_cart_button_id)).click();
    }
    public void clickContinueShopping() throws Exception{
        driver.findElement(By.xpath(CartPageVariables.contibue_shopping_link_xpath)).click();
    }
    public void clickCheckOut() throws Exception{
        driver.findElement(By.id(CartPageVariables.check_out_button_id)).click();
    }
    public void verifyCartIsLoaded() throws Exception{
        logger.info("We will verify the cart page is loaded");
        String title = getCartPageTitle();
        Assert.assertEquals(title,"SHOPPING CART");
        Assert.assertTrue(driver.findElement(By.id(CartPageVariables.update_cart_button_id)).isDisplayed());
        Assert.assertTrue(driver.findElement(By.id(CartPageVariables.check_out_button_id)).isDisplayed());
        Assert.assertTrue(driver.findElement(By.id(CartPageVariables.promo_code_submit_button_id)).isDisplayed());
        logger.info("Cart page is loaded");
    }
}
